/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package coms.action;

import coms.delegates.ConferenceDelegate;
import coms.delegates.ConferenceItemBookingDelegate;
import coms.delegates.ConferenceItemDelegate;
import coms.dto.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *
 * @author Pk
 */
public class ConferenceItemDetailAction extends ComsActionSupport {

    private String conference;
    private List<ConferenceItem> conferenceItemList;
    private List<ConferenceItemBooking> conferenceItemBookingList;
    private String actionType;
    private ConferenceDelegate conDelegate;
    private ConferenceItemDelegate conItemDelegate;
    private ConferenceItemBookingDelegate conItemBookingDelegate;


    public ConferenceItemDetailAction() {
        
        conItemDelegate=new ConferenceItemDelegate();
        conDelegate=new ConferenceDelegate();
        conItemBookingDelegate=new ConferenceItemBookingDelegate();   
    }    
    
    public List<ConferenceItemBooking> getConferenceItemBookingList() {
        return conferenceItemBookingList;
    }

    public void setConferenceItemBookingList(List<ConferenceItemBooking> conferenceItemBookingList) {
        this.conferenceItemBookingList = conferenceItemBookingList;
    }
    
    public String getActionType() {
        return actionType;
    }

    public void setActionType(String actionType) {
        this.actionType = actionType;
    }

    public List<ConferenceItem> getConferenceItemList() {
        return conferenceItemList;
    }

    public void setConferenceItemList(List<ConferenceItem> conferenceItemList) {
        this.conferenceItemList = conferenceItemList;
    }

    public String getConference() {
        return conference;
    }

    public void setConference(String conference) {
        this.conference = conference;
    }


    public String create() {
        
        Conference conf = conDelegate.getById(Integer.parseInt(conference));
        User u=(User)getSession().get("user");
        ConferenceItemBooking conBook=new ConferenceItemBooking();
        conBook.setParticipant(u);
        conBook.setValid(true);
        List<ConferenceItemBooking> c=conItemBookingDelegate.search(conBook);
        conferenceItemList=new ArrayList<ConferenceItem>();
        for(ConferenceItem con:conf.getConferenceItemList())
        {
            if(!c.contains(con))
            {
                conferenceItemList.add(con);
            }
        }        
        System.out.println(conferenceItemList.size());
        actionType = "confirmBooking";
        return "create";
    }

    public String delete() {
        actionType = "cancelBooking";
        Map<String, Object> session = getSession();
        User u=(User)session.get("user");
        Conference conf = conDelegate.getById(Integer.parseInt(conference));
        
        System.out.println("User Id"+u.getId());
        System.out.println("Conf Id"+conf.getId());
        
        conferenceItemBookingList=conItemBookingDelegate.getConferenceItemBookingByParticipant(u, conf);
        return "cancel";
    }
}
